package com.example.demo.jvm;

/**
 * @author liweizhi
 * @date 2020/4/7 17:54
 */
public class InitializingTest {
    public static void main(String[] args) throws ClassNotFoundException {
//        System.out.println(Parent.a); // 先加载Parent,然后打印a
//        System.out.println(Parent.s);
//        System.out.println(Child.q); // 先加载Parent, 后加载Child, 然后打印q
//        System.out.println(Child.w);
//            Class.forName("com.example.demo.jvm.InitializingTest$Parent");
        // 这个和打印Child.q时一样, 其实就是当第一次打印Child.q,去加载了
//        Class.forName("com.example.demo.jvm.InitializingTest$Child");

        Child child = new Child();
    }

    static class Parent {
        static int a = 1;
        static final int s = 2;

        static {
            System.out.println("Parent static block");
        }

        {
            System.out.println("Patent block");
        }

        public Parent() {
            System.out.println("Patent constructor");
        }

    }

    static class Child extends Parent {
        static int q = 3;
        static final int w = 4;

        static {
            System.out.println("Child static block");
        }


        {
            System.out.println("Child block");
        }

        public Child() {
            System.out.println("Child constructor");
        }
    }
}
